package extract;

import control.CConnection;
import control.CSerpent;
import control.CSpecies;
import control.CMember;
import control.CRegion;
import model.Member;
import model.Serpent;
import model.Specie;
import model.Region;

import java.util.ArrayList;
import java.util.Random;
import java.sql.*;

public class ExtractSerpent {
	public static void main(String args[]) {
		CConnection cn = new CConnection();
		
		try {
			cn.createConnection();
			CSerpent cs = new CSerpent(cn);
			Random randSpecie = new Random();
			Random randMember = new Random();
			Random randRegion = new Random();
			
			CSpecies cspecie= new CSpecies(cn);
            ArrayList<Specie> species = cspecie.retrieveAll();
            CMember cmember = new CMember(cn);
            ArrayList<Member> members = cmember.retrieveAll();
            CRegion cregion = new CRegion(cn);
            ArrayList<Region> regions = cregion.retrieveAll();
            
        	Serpent s = new Serpent();
        	for (int i = 0; i < 250; i++)
            {
            	s.setSerpentID(i);
            	s.setMemberID(members.get(randMember.nextInt(members.size())).getUserID());
                s.setRegionID(regions.get(randRegion.nextInt(regions.size())).getRegionID());
                s.setSpecie(species.get(randSpecie.nextInt(species.size())).getScientificName());
                cs.create(s);
            }
			
			System.out.println("Serpents added successfully.");
		}
		catch (ClassNotFoundException e) {
			System.err.println("Couldn't connect to Derby Database.");
		}
		catch (SQLException e) {
			System.err.println("Error in SQL Statement.");
		}
	}
}